package com.ruoyi.duty.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.duty.domain.DutyShift;
import com.ruoyi.duty.service.IDutyShiftService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 班次信息Controller
 * 
 * @author yepanpan
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/duty/shift")
public class DutyShiftController extends BaseController
{
    @Autowired
    private IDutyShiftService dutyShiftService;

    /**
     * 查询班次信息列表
     */
    @PreAuthorize("@ss.hasPermi('duty:shift:list')")
    @GetMapping("/list")
    public TableDataInfo list(DutyShift dutyShift)
    {
        startPage();
        List<DutyShift> list = dutyShiftService.selectDutyShiftList(dutyShift);
        return getDataTable(list);
    }

    /**
     * 导出班次信息列表
     */
    @PreAuthorize("@ss.hasPermi('duty:shift:export')")
    @Log(title = "班次信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DutyShift dutyShift)
    {
        List<DutyShift> list = dutyShiftService.selectDutyShiftList(dutyShift);
        ExcelUtil<DutyShift> util = new ExcelUtil<DutyShift>(DutyShift.class);
        util.exportExcel(response, list, "班次信息数据");
    }


    /**
     * 获取班次信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('duty:shift:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dutyShiftService.selectDutyShiftById(id));
    }

    /**
     * 新增班次信息
     */
    @PreAuthorize("@ss.hasPermi('duty:shift:add')")
    @Log(title = "班次信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody DutyShift dutyShift)
    {
                dutyShift.setCreateBy(getUsername());
        return toAjax(dutyShiftService.insertDutyShift(dutyShift));
    }

    /**
     * 修改班次信息
     */
    @PreAuthorize("@ss.hasPermi('duty:shift:edit')")
    @Log(title = "班次信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody DutyShift dutyShift)
    {
                dutyShift.setUpdateBy(getUsername());
        return toAjax(dutyShiftService.updateDutyShift(dutyShift));
    }

    /**
     * 删除班次信息
     */
    @PreAuthorize("@ss.hasPermi('duty:shift:remove')")
    @Log(title = "班次信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dutyShiftService.deleteDutyShiftByIds(ids));
    }
}
